const normal = require("./data/normal");
let cangshenchu = require("./data/cangshenchu");
let jsonFormat = require("json-format")

let qkMaterial = require("./data/qkMaterial.js");

qkMaterial = qkMaterial.map(item => {
    return {
        q: function (v) { 
            let reg = new RegExp(`部件 *${item.name.trim()}`,"i")
            return reg.test(v)
        },
        a: jsonFormat(item)
    }
})


let QkDatas = require("./data/QkDatas.js")

let ViewList = {
    q: function (v) { 
        let reg = new RegExp(`(查看|show|view) *(.+)$`,"i")
        if(reg.test(v)){
            return QkDatas[RegExp.$2]
        }
    }
};


module.exports = function(props) {
    let {bot, data} = props;
    let {group_id, message} = data;

    bindQA({
        group_ids: [368074699, 747029011],
        group_id,
        bot,
        data,
        message,
        qa: normal
    })

    bindQA({
        group_ids: [977610373, 959059974, 747029011],
        group_id,
        bot,
        data,
        message,
        qa: [ViewList, ...qkMaterial, ...cangshenchu]
    })

}

function bindQA(props) {
    let {data, group_ids,group_id, qa,message, bot} = props
    if(group_ids.includes(group_id) && bot.gl.has(group_id)) {
        qa.forEach(item => {
            if(message[0].type=="text") {
                let qs = item.q(message[0].data.text);
                if(qs) {
                    if(item.a) {
                        data.reply(item.a)
                    } else {
                        data.reply(qs)
                    }
                }
            }
        });
    }
}

